package cn.itsource.order.controller;


import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.basic.utils.SystemContext;
import cn.itsource.order.service.IAdoptOrderService;
import cn.itsource.user.domain.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 领养订单
 */

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;


    /**
     * 提交领养订单
     * @param param {addressId:1,petId:4,payType:3}
     * @return
     */
    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody Map<String,Long> param, HttpServletRequest request){
        try {
            LoginInfo loginInfo = SystemContext.getLoginInfo(request);
            adoptOrderService.submitOrder(param, loginInfo);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
